package com.briup.smartlabs.service.impl;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.briup.smartlabs.bean.SmartEnvDetail;
import com.briup.smartlabs.bean.ex.EnvStatisticData;
import com.briup.smartlabs.mapper.SmartEnvDetailMapper;
import com.briup.smartlabs.mapper.ex.EnvStatisticMapper;
import com.briup.smartlabs.service.SmartEnvService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

@Service
public class SmartEnvServiceImpl implements SmartEnvService {
	@Autowired
	private EnvStatisticMapper statisticMapper;
	
	@Autowired
	private SmartEnvDetailMapper envDetailMapper;

	@Override
	public List<EnvStatisticData> findByMonth(String date) {
		System.out.println("date:"+date+"====="+StringUtils.isEmpty(date));
		if(StringUtils.isEmpty(date)) {
			Calendar c = Calendar.getInstance();
			date = (1970+c.get(Calendar.YEAR))+"-"+c.get(Calendar.MONTH);
			System.out.println(date);
		}
		return statisticMapper.byMonth(date);
	}

	// 实现类SmartEnvServiceImpl.java中
	@Override
	public PageInfo<SmartEnvDetail> findAllByPage(
			Integer pageNum, Integer pageSize, Date start, Date end, String type) {
		//分页+条件查询
		//1.开启分页查询
		PageHelper.startPage(pageNum,pageSize);

		//2.执行常规条件查询
		List<SmartEnvDetail> list = envDetailMapper.findAllByCondition(start, end, type);

		//3.封装查询数据到 PageInfo对象中
        //4.返回结果
		return new PageInfo<>(list);
	}

	@Override
	public List<EnvStatisticData> findByYear(String year) {
		if(StringUtils.isEmpty(year)) {
			Calendar c = Calendar.getInstance();
			year = (1970+c.get(Calendar.YEAR))+"";
		}
		return statisticMapper.byYear(year);
	}

}


